package com.zkadmin.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zkadmin.auditor.SysUserAuditorAware;

@Aspect
@Component
public class SysLogAspect {
	@Autowired
	private SysUserAuditorAware sysUserAuditorAware;


	@Pointcut("@annotation(com.zkadmin.annotation.SysServiceLog)")
	public void serviceLogAspect() {
	}

	@AfterReturning(value = "serviceLogAspect()")
	public void serviceLog(JoinPoint joinPoint) throws Throwable {
		/*SysUser sysUser = sysUserAuditorAware.getCurrentAuditor();
		StringBuffer descn = new StringBuffer();
		Method[] methods = joinPoint.getTarget().getClass().getMethods();
		for (Method method : methods) {
			if (method.getName().equals(joinPoint.getSignature().getName())) {
				Annotation[] annotations = method.getAnnotations();
				for (Annotation annotation : annotations) {
					if (annotation instanceof SysServiceLog) {
						SysServiceLog sysServiceLog = (SysServiceLog) annotation;
						descn.append(sysServiceLog.descn());
						break;
					}
				}
				break;
			}
		}

		Object[] args = joinPoint.getArgs();
		for (Object arg : args) {
			descn.append("|");
			descn.append(arg.toString());
		}

		SysLog sysLog = new SysLog(sysUser, descn.toString(), new Date());
		sysLogService.save(sysLog);*/
	}
}
